package org.agony2d.view.supportClasses 
{
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.agony2d.view.ButtonType;
	
	import org.agony2d.core.agony_internal;
	use namespace agony_internal;
	
	/**
	 * @tips
	 * 		未选中(1-3) - 未选中无效(4) - 选中(5-7) - 选中无效(8)
	 */
public class ImageCheckBoxProp extends ImageButtonProp 
{
	
	final agony_internal function get selectedPress() : BitmapData { return selectedPressImage }
	final agony_internal function get selectedRelease() : BitmapData { return selectedReleaseImage }
	final agony_internal function get selectedInvalid() : BitmapData { return selectedInvalidImage }
	final agony_internal function get selectedLeave() : BitmapData { return (effectType & ButtonType.PRESS_PRESS) ? selectedPressImage : selectedReleaseImage }
	final agony_internal function get selectedHover() : BitmapData { return (effectType & (ButtonType.PRESS_PRESS | ButtonType.LEAVE_PRESS)) ? selectedPressImage : selectedReleaseImage }
	
	
	final override agony_internal function initialize( source:BitmapData, hasInvalid:Boolean ) : void
	{
		var width:Number, height:Number
		var rect:Rectangle
		var point:Point
		
		width   =  source.width / 2
		height  =  hasInvalid ? (source.height / 3) : (source.height / 2)
		point   =  new Point()
		rect    =  new Rectangle(width, 0, width, height)
		
		if (hasInvalid)
		{
			selectedPressImage = new BitmapData(width, height, true, 0x0)
			selectedPressImage.copyPixels(source, rect, point)
			selectedReleaseImage = new BitmapData(width, height, true, 0x0)
			rect.y = height
			selectedReleaseImage.copyPixels(source, rect, point)
			selectedInvalidImage = new BitmapData(width, height, true, 0x0)
			rect.y = height * 2
			selectedInvalidImage.copyPixels(source, rect, point)
		}
		
		else
		{
			selectedPressImage = new BitmapData(width, height, true, 0x0)
			selectedPressImage.copyPixels(source, rect, point)
			selectedReleaseImage = new BitmapData(width, height, true, 0x0)
			rect.y = height
			selectedReleaseImage.copyPixels(source, rect, point)
		}
		
		super.initialize(source, hasInvalid)
	}
	
	override agony_internal function dispose() : void
	{
		super.dispose()
		selectedPressImage.dispose()
		selectedPressImage = null
		selectedReleaseImage.dispose()
		selectedReleaseImage = null
		if (selectedInvalidImage)
		{
			selectedInvalidImage.dispose()
			selectedInvalidImage = null
		}
	}
	
	
	agony_internal var selectedPressImage:BitmapData, selectedReleaseImage:BitmapData, selectedInvalidImage:BitmapData
}
}